cmake_minimum_required(VERSION 3.0.2)
project(dataflow_publisher)
set(CMAKE_CXX_STANDARD 11)

find_package(catkin REQUIRED COMPONENTS
        cv_bridge
        image_transport
        roscpp
        rospy
        sensor_msgs
        std_msgs
        camera_info_manager
        )

find_package(PkgConfig REQUIRED)
pkg_check_modules(GLOG IMPORTED_TARGET libglog)

catkin_package(
        INCLUDE_DIRS include
        LIBRARIES dataflow_publisher
        CATKIN_DEPENDS cv_bridge image_transport roscpp rospy sensor_msgs std_msgs
#        DEPENDS system_lib
)

include_directories(
    include
    ${catkin_INCLUDE_DIRS}
)

file(GLOB_RECURSE HEADERS "include/*.h")
file(GLOB_RECURSE SOURCES "src/*.cpp")
file(GLOB_RECURSE TESTS "test/*.cpp")
message(STATUS "Header files: ${HEADERS}")
message(STATUS "Source files: ${SOURCES}")
message(STATUS "Test files: ${TESTS}")

set(TARGET_IMU_PUB ON)
set(TARGET_IMU_PUB_TEST ON)

if (${TARGET_IMU_PUB})
    set(TARGET_NAME "imu_publisher")
    message(STATUS "Add target ${TARGET_NAME}")
    add_executable(${TARGET_NAME} node_src/imu_publisher_node.cpp)
    target_sources(${TARGET_NAME} PUBLIC ${HEADERS})
    target_sources(${TARGET_NAME} PUBLIC ${SOURCES})
    target_link_libraries(${TARGET_NAME} ${catkin_LIBRARIES})
endif ()

if (${TARGET_IMU_PUB_TEST})
    set(TARGET_NAME "imu_publisher_test")
    message(STATUS "Add target ${TARGET_NAME}")
    add_executable(${TARGET_NAME} test/imu_pub_test.cpp)
    target_sources(${TARGET_NAME} PUBLIC ${HEADERS})
    target_sources(${TARGET_NAME} PUBLIC ${SOURCES})
    target_sources(${TARGET_NAME} PUBLIC ${TESTS})
    target_link_libraries(${TARGET_NAME} ${catkin_LIBRARIES})
    if (GLOG_FOUND)
        add_definitions(-DENABLE_GLOG)
        message(STATUS "Found GLOG: ${GLOG_LINK_LIBRARIES}")
        message(STATUS "  headers: ${GLOG_INCLUDE_DIRS}")
        message(STATUS "  libs: ${GLOG_LIBRARIES}")
        target_link_libraries(${TARGET_NAME} PkgConfig::GLOG)
    endif ()
endif ()
